//
//  HMNavigaViewController.swift
//  SinaWeiBo
//
//  Created by immncjykeny on 2017/4/21.
//  Copyright © 2017年 immncjykeny. All rights reserved.
//

import UIKit

class HMNavigaViewController: UINavigationController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //隐藏默认的navigationBar
        navigationBar.isHidden = true
    }
    ///MARK:重写push方法 隐藏tabbar
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if childViewControllers.count > 0 {
            
            viewController.hidesBottomBarWhenPushed = true
            
            //判断控制器类型
            if let vc = viewController as? HMBaseViewController  {
                
                var title = "返回"
                //判断控制器的级数 如果只有一个时候 显示首页标题
                if childViewControllers.count == 1 {
                    title = childViewControllers.first?.title ?? "返回"
                    
                }
                vc.navigaItem.leftBarButtonItem = UIBarButtonItem(title: title, action: #selector(popToPreviewsVc), target: self,isBack:true)
            }
        }
        super.pushViewController(viewController, animated: true)
    }
    func popToPreviewsVc(){
        
        popViewController(animated: true)
    }

}
